﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using yunbo.Model.SSM;
using yunbo.Repositorys.SSMRepositorys;

namespace yunbo.Controllers.SSMControllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class PostController : ControllerBase
    {
        PostRepository postRepository = new PostRepository();
        [HttpGet("GetFYPost")]
        public IActionResult GetFYPost(int PageNumber, int PageSize)
        {
            var posts = postRepository.GetFYPost(PageNumber, PageSize);
            return Ok(posts);
        }
        [HttpGet("MHCX")]
        public IActionResult MHCX(int PageNumber, int PageSize, int? status, string? name)
        {
            var postc = postRepository.MHCX(PageNumber, PageSize,status,name);
            return Ok(postc);
        }
        [HttpPost("AddPost")]
        public IActionResult AddPost(TJPost post)
        {
            Post post1 = new Post() 
            {
                post_name= post.post_name,
                post_sort=post.post_sort,
                post_code=post.post_code,
                post_create_by=post.post_create_by,
                post_status=1,
                post_notes=post.post_notes,
                post_create_time=DateTime.Now,
            };
            bool postok = postRepository.AddPost(post1)>0;
            return Ok(postok);
        }
        [HttpPut("UpPost")]
        public IActionResult UpPost(XGPost post)
        {
            Post post2 = new Post()
            {
                post_id = post.post_id,
                post_name = post.post_name,
                post_sort = post.post_sort,
                post_code = post.post_code,
                post_update_by = post.post_update_by,
                post_status = post.post_status,
                post_notes = post.post_notes,
                post_update_time = DateTime.Now,
            };
            bool postok2 = postRepository.UpPost(post2) > 0;
            return Ok(postok2);
        }
        [HttpDelete("DePost")]
        public IActionResult DePost(int id)
        {
            bool postok3 = postRepository.DePost(id) > 0;
            return Ok(postok3);
        }

        [HttpPut("UPstatus")]
        public IActionResult UPstatus(int id, int status)
        {

            bool status1 = postRepository.Upstatus(id, status) > 0;
            return Ok(status1);
        }

    }
}
